package com.example.testapp.activity.activity.study;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.testapp.R;
import com.example.testapp.activity.activity.SuperActivity;
import com.example.testapp.activity.adapter.SuperViewPagerAdapter;
import com.example.testapp.activity.ui.viewgroup.FreshBolgLayout;
import com.example.testapp.activity.ui.viewgroup.HotsBolgLayout;
import com.example.testapp.activity.view.pager.SuperViewPager;

import java.util.ArrayList;

/**
 * Created by l on 2016/9/1.
 */
public class BolgsShareActivity extends SuperActivity {

    private ViewPager mViewPager;
    private TextView  mNewsBlog;
    private TextView  mHotsBlog;
    private SuperViewPagerAdapter mPagerAdapter;

    private FreshBolgLayout  mFreshBolgLayout;
    private HotsBolgLayout   mHotsBolgLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_blog_share);
        getWindow().setBackgroundDrawable(null);
        initView();
    }

    private void initView() {
        RelativeLayout layout = (RelativeLayout) this.findViewById(R.id.back_left);
        layout.setOnClickListener(mOnClickListener);
        LinearLayout  linear = (LinearLayout) this.findViewById(R.id.head_filter);
        mNewsBlog = (TextView) linear.findViewById(R.id.news_blog);
        mHotsBlog = (TextView) linear.findViewById(R.id.hots_blog);
        mNewsBlog.setOnClickListener(mOnClickListener);
        mHotsBlog.setOnClickListener(mOnClickListener);
        mViewPager = (ViewPager) this.findViewById(R.id.super_viewpager);

        initFilter();

        mFreshBolgLayout = new FreshBolgLayout(mContext);
        mHotsBolgLayout = new HotsBolgLayout(mContext);

        ArrayList<View> views = new ArrayList<View>();
        views.add(mFreshBolgLayout);
        views.add(mHotsBolgLayout);
        mPagerAdapter = new SuperViewPagerAdapter(views);
        mViewPager.setAdapter(mPagerAdapter);

        mFreshBolgLayout.loadFreshBolgInfo(true);
        mHotsBolgLayout.loadHotsBolgInfo(true);
    }

    /**
     * 初始化导航过滤器
     */
    private void initFilter() {
       mNewsBlog.setTextColor(mContext.getResources().getColor(R.color.white));
       mNewsBlog.setBackgroundResource(R.drawable.select_nofinish_filter_pressed);
       mHotsBlog.setTextColor(mContext.getResources().getColor(R.color.FF545A));
       mHotsBlog.setBackgroundResource(R.drawable.select_finished_filter_normal);
    }

    public View.OnClickListener mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           switch (v.getId()){
               case R.id.back_left:
                   finish();
                   break;
               case R.id.news_blog:
                   handlerFilter(0);
                   mViewPager.setCurrentItem(0);
                   break;
               case R.id.hots_blog:
                   handlerFilter(1);
                   mViewPager.setCurrentItem(1);
                   break;
               default:
                   break;
           }
        }
    };

    /**
     * 处理选中的导航过滤器
     * @param position
     */
    private void handlerFilter(int position) {
       switch (position){
           case 0:
               mNewsBlog.setTextColor(mContext.getResources().getColor(R.color.white));
               mNewsBlog.setBackgroundResource(R.drawable.select_nofinish_filter_pressed);
               mHotsBlog.setTextColor(mContext.getResources().getColor(R.color.FF545A));
               mHotsBlog.setBackgroundResource(R.drawable.select_finished_filter_normal);
               break;
           case 1:
               mNewsBlog.setTextColor(mContext.getResources().getColor(R.color.FF545A));
               mNewsBlog.setBackgroundResource(R.drawable.select_finished_filter_normal);
               mHotsBlog.setTextColor(mContext.getResources().getColor(R.color.white));
               mHotsBlog.setBackgroundResource(R.drawable.select_nofinish_filter_pressed);
               break;
           default:
               break;
       }
    }

    @Override
    protected void obtainInfo() {

    }
}
